import { useState } from 'react';

import Modals from '@/components/modals/Modals';

import SelectDataset, { SelectedDataset } from '.';

interface Props {
  open: boolean;
  appId: string;
  confirm: (selectedDatasets: SelectedDataset[]) => void;
  cancel: () => void;
  defaultValue?: SelectedDataset[];
}

const SelectDatasetModal = ({ open, appId, confirm, cancel, defaultValue = [] }: Props) => {
  // 获取SelectDataset 选中的数据
  const [selectedDatasets, setSelectedDatasets] = useState<SelectedDataset[]>([]);

  return (
    <Modals
      open={open}
      line={false}
      title="选择可问答知识库"
      onOk={() => {
        confirm(selectedDatasets);
      }}
      onCancel={cancel}
      width={720}
      destroyOnHidden
    >
      <SelectDataset appId={appId} onSelect={setSelectedDatasets} defaultValue={defaultValue} />
    </Modals>
  );
};

export default SelectDatasetModal;
